package com.one.controller;

import com.one.annotation.RequestPermission;
import com.one.annotation.RequestUser;
import com.one.service.OrderFlashSaleService;
import com.one.service.SignService;
import com.one.util.RequestReturn;
import com.one.util.RequestReturnFactory;
import com.one.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Map;

/**
 * Create on 2022-01-20
 * <p>
 * Author: LiangWei
 * <p>
 * Description:
 **/
@Api(tags = "H.用户签到操作")
@RestController
public class SignController {
    @Autowired
    private SignService signService;
    /**
     * 签到
     */
    @ApiOperation(value = "签到")
    @GetMapping("/doSig")
    @RequestPermission
    RequestReturn<String> doSig(@ApiIgnore @RequestUser UserVo userVo){
        return signService.doSign(userVo.getUserId());
    }

    /**
     * 查询用户当天是否已经签到
     */
    @ApiOperation(value = "查询用户当天是否已签到")
    @GetMapping("/checkSig")
    @RequestPermission
    @ApiImplicitParam(name = "date", required = true, value = "日期")
    RequestReturn<String> checkSig(@ApiIgnore @RequestUser UserVo userVo, @RequestParam String date){

        return signService.checkSign(userVo.getUserId(),date);
    }

    /**
     * 查询用户某个月的签到次数
     */
    @ApiOperation(value = "查询用户某个月的签到次数")
    @GetMapping("/getSignCountOneMont")
    @RequestPermission
    @ApiImplicitParam(name = "date", required = true, value = "日期")
    RequestReturn<Long> getSignCountOneMont(@ApiIgnore @RequestUser UserVo userVo,@RequestParam String date){
        return signService.getSignCountOneMonth(userVo.getUserId(),date);
    }

    /**
     * 获取用户某个月连续签到次数
     */
    @ApiOperation(value = "获取用户某个月连续签到次数")
    @GetMapping("/getContinuousSignCoun")
    @RequestPermission
    @ApiImplicitParam(name = "date", required = true, value = "日期")
    RequestReturn<Long> getContinuousSignCoun(@ApiIgnore @RequestUser UserVo userVo,@RequestParam String date){
        return signService.getContinuousSignCount(userVo.getUserId(),date);
    }

    /**
     * 获取用户某个月第一次签到的日期
     */
////    @ApiOperation(value = "获取用户某个月第一次签到的日期")
//    @GetMapping("/getFirstSignDat")
//    @RequestPermission
////    @ApiImplicitParam(name = "date", required = true, value = "日期")
//    RequestReturn<String> getFirstSignDat(@ApiIgnore @RequestUser UserVo userVo, @RequestParam String date){
////        return signService.getFirstSignDate(userVo.getUserId(),date);
//        LocalDate localDate= signService.getFirstSignDate(userVo.getUserId(),date).getData();
//        String format = localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
//        return RequestReturnFactory.success(format);
//    }

    /**
     * 获取用户某个月的签到流水
     */
    @ApiOperation(value = "获取用户某个月的签到流水")
    @GetMapping("/getSignInf")
    @RequestPermission
    @ApiImplicitParam(name = "date", required = true, value = "日期")
    RequestReturn<Map<String,Boolean>> getSignInf(@ApiIgnore @RequestUser UserVo userVo, @RequestParam String date){
        return signService.getSignInfo(userVo.getUserId(),date);
    }

    /**
     * 获取用户当月最多连续签到次数
     */
    @ApiOperation(value = "获取用户当月最多连续签到次数")
    @GetMapping("/getContinuousSignCountByTotalMont")
    @RequestPermission
    @ApiImplicitParam(name = "date", required = true, value = "日期")
    RequestReturn<Long> getContinuousSignCountByTotalMont(@ApiIgnore @RequestUser UserVo userVo,@RequestParam String date){
        return signService.getContinuousSignCountByTotalMonth(userVo.getUserId(),date);
    }
    /**
     * 补签（测试）
     */
    @ApiOperation(value = "指定某天签到（Test）")
    @GetMapping("/Buq")
    @RequestPermission
    @ApiImplicitParam(name = "date", required = true, value = "日期")
    RequestReturn<String> getContinuousSignCountB(@ApiIgnore @RequestUser UserVo userVo,@RequestParam String date){
        return signService.getContinuousSignCountBQ(userVo.getUserId(),date);
    }
}
